package com.woniuxy.joylifeforum.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.common.utils.JWTUtils;
import com.woniuxy.joylifeforum.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 话题相关处理 话题详情  点赞 收藏 评论 举报
 */
@RestController
public class TopicController {
    @Autowired
    private TopicService topicService;
    /*
    查看话题详情
     */
    @RequestMapping("/lookTopic")
    public Object lookTopic(HttpServletRequest request,String topicId){
        //用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        Map<String, Object> data = topicService.findTopicCont(topicId,userId);
        data.put("code",200);
        data.put("mes","ok");
        return data;
    }
    /*
    查看话题回复
     */
    @RequestMapping("/lookReply")
    public Object lookReply(HttpServletRequest request,Integer page, Integer limit,String topicId){
        //用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        Map<String, Object> result=new HashMap<>();
        PageInfo<Map<String, Object>> data = topicService.findReplyCont(userId,page, limit, topicId);
        result.put("data",data);
        result.put("code",200);
        result.put("mes","ok");
        return result;
    }
    /*
    添加话题回复
     */
    @RequestMapping("/addReply")
    public Object addReply(HttpServletRequest request,HttpServletRequest req, String topicId, String content){
        //图片
        String[] imgs = req.getParameterValues("imgs[]");
        //用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        Map<String, Object> result=new HashMap<>();
        String data = topicService.addReplyService(imgs, topicId, null, content, userId, null);
        result.put("data",data);
        result.put("code",200);
        result.put("mes","ok");
        return result;
    }
        /*
        对回复赞状态更改
         */
        @RequestMapping("/alterPraise")
        public Object alterPraise(HttpServletRequest request,String replyId){
            //用户id
            //String userId="111";
            String userId = JWTUtils.getUserId(request.getHeader("token"));
            Integer status = topicService.alterPraiseService(userId, replyId);
            Map<String, Object> result=new HashMap<>();
            result.put("status",status);
            result.put("code",200);
            result.put("mes","ok");
            return result;
        }
        /*
        对话题点赞状态更改
         */
    @RequestMapping("/alterTopicPraise")
    public Object alterTopicPraise(HttpServletRequest request,String topicId){
        //用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        Integer status = topicService.alterTopicPraiseService(userId,topicId);
        Map<String, Object> result=new HashMap<>();
        result.put("status",status);
        result.put("code",200);
        result.put("mes","ok");
        return result;
    }
    /*
        收藏状态更改
         */
    @RequestMapping("/collectTopic")
    public Object collectTopic(HttpServletRequest request,String topicId){
        //用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        Integer status = topicService.alterCollectTopicService(userId,topicId);
        Map<String, Object> result=new HashMap<>();
        result.put("status",status);
        result.put("code",200);
        result.put("mes","ok");
        return result;
    }
    /*
        获取楼层回复信息
         */
    @RequestMapping("/replyMes")
    public Object replyMes(HttpServletRequest request,String replyId){
        //用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        Map<String, Object> data = topicService.findReplyService(userId, replyId);
        data.put("code",200);
        data.put("mes","ok");
        return data;
    }
    /*
    回复的回复
     */
    @RequestMapping("/addReplyReply")
    public Object addReplyReply(HttpServletRequest request,String topicId,String floorId,String content,String replyUserId){
        //用户id
        //System.out.println(floorId==null);
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        String data = topicService.addReplyService(null, topicId, floorId, content, userId, replyUserId);
        Map<String, Object> result=new HashMap<>();
        result.put("data",data);
        result.put("code",200);
        result.put("mes","ok");
        return result;
    }
    /*
   举报
    */
    @RequestMapping("/addInform")
    public Object addInform(HttpServletRequest request,String topicId,String floorId,String content) {
        //获取用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        Integer data = topicService.addInform(userId,topicId, floorId, content);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("mes", "OK");
        result.put("data", data);
        return result;
    }
    /*
   查询话题举报
    */
    @RequestMapping("/topicTnform")
    public Object topicTnform(HttpServletRequest request,Integer page, Integer limit,String forumId) {
        //获取用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        PageInfo<Map<String, Object>> data = topicService.topicTnformService(userId, page, limit, forumId);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("mes", "OK");
        result.put("data", data);
        return result;
    }

    /*
    话题举报审核提交
     */
    @RequestMapping("/checkTopicInform")
    public Object checkTopicInform(HttpServletRequest request,String informId,Integer status) {
        //获取用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        Integer data = topicService.checkTopicInformService(userId, informId, status);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("mes", "OK");
        result.put("data", data);
        return result;
    }
    /*
   查询回复举报
    */
    @RequestMapping("/replyInform")
    public Object replyInform(HttpServletRequest request,Integer page, Integer limit,String forumId) {
        //获取用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        PageInfo<Map<String, Object>> data = topicService.replyTnformService(userId, page, limit, forumId);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("mes", "OK");
        result.put("data", data);
        return result;
    }
    /*
   回复举报审核提交
    */
    @RequestMapping("/checkReplyInform")
    public Object checkReplyInform(HttpServletRequest request,String informId,Integer status) {
        //获取用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        Integer data = topicService.checkReplyInformService(userId, informId, status);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("mes", "OK");
        result.put("data", data);
        return result;
    }
}
